#ifndef __TICLOG_H__
#define __TICLOG_H__

#include "easylogging++.h"
#include <ros/ros.h>

//------------------------------定义 开始-------------------------

//使用easylog
#define ENABLE_EASY_LOG         1
//使用ros自带log
#define ENABLE_ROS_LOG          2
//同时使用easylog和ros自带log
#define ENABLE_ROS_AND_EASY_LOG 3

//使能
#define ENABLE_LOG   (1)
//失能
#define DISABLE_LOG  (0)

void ticSaveLogToFile(int8_t leve, const char *format, ...);
//------------------------------定义 结束-------------------------


//------------------------------日志系统配置 开始-------------------------

// ENABLE_EASY_LOG 使用easylog
// ENABLE_ROS_LOG  使用ros自带log
// ENABLE_ROS_AND_EASY_LOG 同时使用easylog和ros自带log
#define DEFAULT_LOG ENABLE_ROS_AND_EASY_LOG


//ENABLE_LOG 使能
//DISABLE_LOG 失能

//是否在屏幕上打印
#define STANDARD_OUTPUT ENABLE_LOG

//是否以流形式输出
#define FLOW_FORM_OUTPUT DISABLE_LOG

//保存日志目录的个数
#define LOG_SAVE_NUMBER  7

//------------------------------日志系统配置 结束-------------------------

void initLogSyatem(void);

#if DEFAULT_LOG == ENABLE_EASY_LOG

#if FLOW_FORM_OUTPUT == ENABLE_LOG
    #define TIC_DEBUG(...)   {initLogSyatem(); LOG(DEBUG)     << __VA_ARGS__;}
    #define TIC_INFO(...)    {initLogSyatem(); LOG(INFO)      << __VA_ARGS__;}
    #define TIC_WARN(...)    {initLogSyatem(); LOG(WARNING)   << __VA_ARGS__;}
    #define TIC_ERROR(...)   {initLogSyatem(); LOG(ERROR)     << __VA_ARGS__;}
    #define TIC_FATAL(...)   {initLogSyatem(); LOG(FATAL)     << __VA_ARGS__;}
    #define TIC_TRACE(...)   {initLogSyatem(); LOG(TRACE)     << __VA_ARGS__;}
#else
    #define TIC_DEBUG(...)   {initLogSyatem(); ticSaveLogToFile( 0, __VA_ARGS__);}
    #define TIC_INFO(...)    {initLogSyatem(); ticSaveLogToFile( 1, __VA_ARGS__);}
    #define TIC_WARN(...)    {initLogSyatem(); ticSaveLogToFile( 2, __VA_ARGS__);}
    #define TIC_ERROR(...)   {initLogSyatem(); ticSaveLogToFile( 3, __VA_ARGS__);}
    #define TIC_FATAL(...)   {initLogSyatem(); ticSaveLogToFile( 4, __VA_ARGS__);}
    #define TIC_TRACE(...)   {initLogSyatem(); ticSaveLogToFile( 5, __VA_ARGS__);}
#endif

#elif DEFAULT_LOG == ENABLE_ROS_LOG

    #define TIC_DEBUG(...)  ROS_DEBUG(__VA_ARGS__)
    #define TIC_INFO(...)   ROS_INFO(__VA_ARGS__)
    #define TIC_WARN(...)   ROS_WARN(__VA_ARGS__)
    #define TIC_ERROR(...)  ROS_ERROR(__VA_ARGS__)
    #define TIC_FATAL(...)  ROS_FATAL(__VA_ARGS__)
    #define TIC_TRACE(...)  ROS_INFO(__VA_ARGS__)

#elif DEFAULT_LOG == ENABLE_ROS_AND_EASY_LOG

#if FLOW_FORM_OUTPUT == ENABLE_LOG
    #define TIC_DEBUG(...)  {initLogSyatem(); LOG(DEBUG)     << __VA_ARGS__; ROS_DEBUG(__VA_ARGS__);}
    #define TIC_INFO(...)   {initLogSyatem(); LOG(INFO)      << __VA_ARGS__; ROS_INFO(__VA_ARGS__) ;}
    #define TIC_WARN(...)   {initLogSyatem(); LOG(WARNING)   << __VA_ARGS__; ROS_WARN(__VA_ARGS__) ;}
    #define TIC_ERROR(...)  {initLogSyatem(); LOG(ERROR)     << __VA_ARGS__; ROS_ERROR(__VA_ARGS__);}
    #define TIC_FATAL(...)  {initLogSyatem(); LOG(FATAL)     << __VA_ARGS__; ROS_FATAL(__VA_ARGS__);}
    #define TIC_TRACE(...)  {initLogSyatem(); LOG(TRACE)     << __VA_ARGS__; ROS_INFO(__VA_ARGS__) ;}
#else
    #define TIC_DEBUG(...)  {initLogSyatem(); ticSaveLogToFile( 0, __VA_ARGS__); ROS_DEBUG(__VA_ARGS__);}
    #define TIC_INFO(...)   {initLogSyatem(); ticSaveLogToFile( 1, __VA_ARGS__); ROS_INFO(__VA_ARGS__) ;}
    #define TIC_WARN(...)   {initLogSyatem(); ticSaveLogToFile( 2, __VA_ARGS__); ROS_WARN(__VA_ARGS__) ;}
    #define TIC_ERROR(...)  {initLogSyatem(); ticSaveLogToFile( 3, __VA_ARGS__); ROS_ERROR(__VA_ARGS__);}
    #define TIC_FATAL(...)  {initLogSyatem(); ticSaveLogToFile( 4, __VA_ARGS__); ROS_FATAL(__VA_ARGS__);}
    #define TIC_TRACE(...)  {initLogSyatem(); ticSaveLogToFile( 5, __VA_ARGS__); ROS_INFO(__VA_ARGS__) ;}
#endif

#else

#error ticlog.h ---> "DEFAULT_LOG" undefined

#endif

//同时使用easylog和ros自带log
#if FLOW_FORM_OUTPUT == ENABLE_LOG
    #define TIC_LOG_DEBUG(...)  {initLogSyatem(); LOG(DEBUG)     << __VA_ARGS__; ROS_DEBUG(__VA_ARGS__);}
    #define TIC_LOG_INFO(...)   {initLogSyatem(); LOG(INFO)      << __VA_ARGS__; ROS_INFO(__VA_ARGS__) ;}
    #define TIC_LOG_WARN(...)   {initLogSyatem(); LOG(WARNING)   << __VA_ARGS__; ROS_WARN(__VA_ARGS__) ;}
    #define TIC_LOG_ERROR(...)  {initLogSyatem(); LOG(ERROR)     << __VA_ARGS__; ROS_ERROR(__VA_ARGS__);}
    #define TIC_LOG_FATAL(...)  {initLogSyatem(); LOG(FATAL)     << __VA_ARGS__; ROS_FATAL(__VA_ARGS__);}
    #define TIC_LOG_TRACE(...)  {initLogSyatem(); LOG(TRACE)     << __VA_ARGS__; ROS_INFO(__VA_ARGS__) ;}
#else
    #define TIC_LOG_DEBUG(...)  {initLogSyatem(); ticSaveLogToFile( 0, __VA_ARGS__); ROS_DEBUG(__VA_ARGS__);}
    #define TIC_LOG_INFO(...)   {initLogSyatem(); ticSaveLogToFile( 1, __VA_ARGS__); ROS_INFO(__VA_ARGS__) ;}
    #define TIC_LOG_WARN(...)   {initLogSyatem(); ticSaveLogToFile( 2, __VA_ARGS__); ROS_WARN(__VA_ARGS__) ;}
    #define TIC_LOG_ERROR(...)  {initLogSyatem(); ticSaveLogToFile( 3, __VA_ARGS__); ROS_ERROR(__VA_ARGS__);}
    #define TIC_LOG_FATAL(...)  {initLogSyatem(); ticSaveLogToFile( 4, __VA_ARGS__); ROS_FATAL(__VA_ARGS__);}
    #define TIC_LOG_TRACE(...)  {initLogSyatem(); ticSaveLogToFile( 5, __VA_ARGS__); ROS_INFO(__VA_ARGS__) ;}
#endif

#endif
